Script ardupilot using LUA
Table of Content
Script ardupilot using LUA#
ArduPilot has introduced support for Lua scripting. Scripting provides a safe, “sandboxed” environment for new behaviors to be added to the autopilot without modifying the core flight code. Scripts are stored on the SD card and run in parallel with the flight code more.
To enable scripting set SCR_ENABLE parameter to 1 and upload scripts to SD APM/scripts folder using mavftp
sitl scripts folder
lua script locate in scripts folder in the root / location of run sitl
Install and config#
Lua#
Config vscode#

copy lua docs from AP_scripting to vscode project root for autocomplete
├── docs.lua
├── params
│ └── lua.param
├── README.md
└── scripts
└── simple_loop.lua
Ardupilot#
| SCR_ENABLE | enable/disable scripts | 1: enable |
| SCR_HEAP_SIZE | usual use default |
Demo#
ardupilot lua hello
local number = math.random()
function update() -- periodic function that will be called
gcs:send_text(0, "hello lua")
gcs:send_named_float("lua float", number)
number = number + math.random()
-- rescheduler the loop
return update, 1000
end
-- Run immdeiately before rescheduler
return update()
check ardupilot ready state
if ahrs:healthy() then
gcs:send_text(0, "hello lua")
end